const path = require("path");
const WebPackBar = require("webpackbar")
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
  // 其他配置...
  plugins: [
    // {
    //   plugin: CracoLessPlugin,
    //   options: {
    //     lessLoaderOptions: {
    //       lessOptions: {
    //         // 修改antd 4 的less样式（自定义主题）
    //         modifyVars: { '@primary-color': '#2e3fe7' },
    //         javascriptEnabled: true,
    //       },
    //     },
    //   },
    // },
  ].filter(Boolean),
  webpack: {
    alias: {
      '@': path.resolve(__dirname, "src"),
      'pages': path.resolve(__dirname, "src/pages"),
      'assets': path.resolve(__dirname, "src/assets"),
      'images': path.resolve(__dirname, "src/assets/images"),
    },
    configure: (webpackConfig, { env, paths }) => {
      let plugins = webpackConfig.plugins;
      if (env === "production") {
        plugins.push(
          new TerserPlugin({  //++++++生产环境则使用这个插件
            terserOptions: {
              ecma: undefined,
              parse: {},
              compress: {
                warnings: false,
                drop_console: true, // 生产环境下移除控制台所有的内容
                drop_debugger: true, // 移除断点
                pure_funcs: ['console.log'] // 生产环境下移除console
              }
            }
          }),
          new WebPackBar()
        )
      }
      webpackConfig.plugins = plugins


      let rules = [
        {
          // 处理其他资源，比如word文档excel等
          test: /\.docx$/,
          type: "asset/resource",
          generator: {
            filename: "static/media/[name][ext][query]"
          }
        },
        ...webpackConfig.module.rules,

      ]
      webpackConfig.module.rules = rules

      webpackConfig.devtool = env === "production" ? false : "inline-source-map"
      return webpackConfig
    }
  },

  devServer: {
    port: "9306",
    proxy: {
      "/personas": {
        target:process.env.REACT_APP_BASE_URL,
        changeOrigin: true,
        pathRewrite: {
          "^/": "/personas/"
        }
      },
      // "/cifgp-core-api": {
      //   target: "http://10.20.88.97:5348",
      //   changeOrigin: true,
      //   pathRewrite: {
      //     "^/": "/cifgp-core-api/"
      //   }
      // },
    }
  }
}

